package com.haois.mp.database.interceptor.configuration;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.haois.mp.database.interceptor.MiniAppInterceptor;
import com.haois.mp.database.module.common.service.IUserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by RuiHaoZ on 2018/1/13 1:50
 */
@Configuration
public class MiniAppInterceptorConfiguration extends WebMvcConfigurerAdapter {
    @Autowired
    private IUserTokenService iUserTokenService;
    @Autowired
    private WxMaService wxMaService;

    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistry = registry.addInterceptor(
                new MiniAppInterceptor(iUserTokenService, wxMaService));
        interceptorRegistry.addPathPatterns("/mini/**");
        interceptorRegistry.excludePathPatterns("/mini/rest/user/register");
        interceptorRegistry.excludePathPatterns("/mini/rest/user/login");
        interceptorRegistry.excludePathPatterns("/mini/rest/user/state");
        interceptorRegistry.excludePathPatterns("/mini/rest/share/**");
        interceptorRegistry.excludePathPatterns("/mini/rest/sys/parameter");

    }
}
